package util.toolkit;

import java.util.ArrayList;
import java.util.List;

import model.TStudent;

/**
 * List工具类
 * @author 徐震霖
 * @since 2018-12-11 9:36
 */
public class ListUtil {

	/**
	 * 删除学生ArrayList中重复元素
	 * @param list 学生对象列表
	 * @return 返回去除重复后的学生对象列表
	 */
    public static List<TStudent> removeDuplicate(List<TStudent> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                if (list.get(j).getIdnumber().equals(list.get(i).getIdnumber())) {
                    list.remove(j);
                }
            }
        }
        return list;
    }
	
	public static void main(String[] args) {
		
		List<TStudent> students = new ArrayList<TStudent>();
		TStudent student = new TStudent();
		student.setBirthday("2018-01-01");
		student.setClassid("0001");
		student.setPwd("");
		student.setRealName("徐震霖");
		student.setSchoolid("yngsxy");
		student.setSex("nan");
		student.setStuid("15612200036");
		students.add(student);

		TStudent student1 = new TStudent();
		student1.setBirthday("2018-01-01");
		student1.setClassid("0001");
		student1.setPwd("");
		student1.setRealName("黄璇");
		student1.setSchoolid("yngsxy");
		student1.setSex("nv");
		student1.setStuid("15612200037");
		students.add(student1);

		TStudent student2 = new TStudent();
		student2.setBirthday("2018-01-01");
		student2.setClassid("0001");
		student2.setPwd("");
		student2.setRealName("黄璇");
		student2.setSchoolid("yngsxy");
		student2.setSex("nv");
		student2.setStuid("15612200037");
		students.add(student2);

		List<TStudent> students2 = removeDuplicate(students);
		for (TStudent tStudent : students2) {
			System.out.println(tStudent.getRealName());
		}

	}

}
